package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Daily;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.DailyQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDailyService;
import cn.wolfcode.trip.base.util.UploadUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/daily")
public class DailyController {
    @Autowired
    private IDailyService dailyService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") DailyQueryObject qo, Model model){
        PageInfo info = dailyService.query(qo);
        model.addAttribute("info",info);
        return "/daily/list";
    }



    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Daily daily, MultipartFile file){
        if ((!file.isEmpty()) && file.getSize() > 0) {
            String url = UploadUtil.upload(file);
            daily.setCoverUrl(url);
        }
        dailyService.saveOrUpdate(daily);
        return "redirect:/daily/list.do";
    }


}
